import 'package:flutter/material.dart';

class PostionPage extends StatefulWidget {
  const PostionPage({super.key});

  @override
  State<PostionPage> createState() => _PostionPageState();
}

class _PostionPageState extends State<PostionPage> {
  GlobalKey key1 = GlobalKey();
  GlobalKey key2 = GlobalKey();
  GlobalKey key3 = GlobalKey();

  ScrollController scrollController = ScrollController();

  @override
  void initState() {
    super.initState();

    scrollController.addListener(() {
      print('${scrollController.offset} --->>');

      RenderBox renderBox =
          key1.currentContext?.findRenderObject() as RenderBox;
      Offset offset = renderBox.localToGlobal(Offset.zero);
      print("${offset} + ${renderBox.paintBounds.height}");

      RenderBox renderBox2 =
          key2.currentContext?.findRenderObject() as RenderBox;
      Offset offset2 = renderBox2.localToGlobal(Offset.zero);
      print("${offset2} + ${renderBox2.paintBounds.height}");

      RenderBox renderBox3 =
          key3.currentContext?.findRenderObject() as RenderBox;
      Offset offset3 = renderBox3.localToGlobal(Offset.zero);
      print("${offset3} + ${renderBox3.paintBounds.height}");
    });


  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        controller: scrollController,
        child: Column(
          children: [
            Container(
              key: key1,
              width: double.maxFinite,
              height: 100,
              color: Colors.red,
            ),
            Container(
              key: key2,
              width: double.maxFinite,
              height: 200,
              color: Colors.blue,
            ),
            Container(
              key: key3,
              width: double.maxFinite,
              height: 1200,
              color: Colors.yellow,
            )
          ],
        ),
      ),
    );
  }
}
